package networkInterface;

import java.io.File;

import cs.remoteapp.FileAnswer;
import cs.remoteapp.FileMessage;
import cs.remoteapp.FileRequest;
import cs.remoteapp.Goodbye;
import cs.remoteapp.Hello;
import cs.remoteapp.Message;
import cs.remoteapp.TextMessage;


/**
 * Creates messages using the Factory pattern
 * 
 * <p>
 * <ul>
 * <li>Project: 	ChatSystemG3</li>
 * <li>Called by: 	networkInterface.*</li>
 * </ul>
 * </p>
 * 
 * @author COMBES Nicolas - LECHANTRE Arnaud
 */
public class MessageFactory {
	
	/**
	 * Contains a short description of every type of message
	 */
	public static enum enum_type_message { HELLO, GOODBYE, TEXT, FILEREQUEST, FILEANSWER, FILE};
	
	
	/**
	 * Gets a new HelloMessage object
	 * @param type (enum_type_message)
	 * @param username name of the message sender
	 * @param isBroadcast
	 * @return the message !
	 */
	public Message getNewMessage(enum_type_message type, String username, Boolean isBroadcast) {
		Message m=null;
		if (type==MessageFactory.enum_type_message.HELLO){
			m = new Hello(username);
			((Hello)m).setBroadcast(isBroadcast);
		} else if (type==MessageFactory.enum_type_message.GOODBYE){
			m = new Goodbye(username);
		}
		return m;
	}

	/**
	 * Gets a new TxtMessage object
	 * @param type (enum_type_message)
	 * @param username name of the message sender
	 * @return the message !
	 */
	public Message getNewMessage(enum_type_message type, String username, String message) {
		Message m=null;
		if (type==MessageFactory.enum_type_message.TEXT){
			m = new TextMessage(username, message);
		}
		return m;
	}

	
	/**
	 * Gets a new FileRequest object
	 * @param type (enum_type_message)
	 * @param username name of the message sender
	 * @param name file name
	 * @param length file size
	 * @return the message !
	 */
	public Message getNewMessage(enum_type_message type, String username, String name, long length) {
		Message m=null;
		if (type==MessageFactory.enum_type_message.FILEREQUEST){
			m = new FileRequest(username, name, length);
		}
		return m;
	}

	
	/**
	 * Gets a new FileAnswer object
	 * @param type (enum_type_message)
	 * @param username name of the message sender
	 * @param name file name
	 * @param accept file is accepted or not
	 * @return the message !
	 */
	public Message getNewMessage(enum_type_message type, String username, String fileName, boolean accept) {
		Message m=null;
		if (type==MessageFactory.enum_type_message.FILEANSWER){
			m = new FileAnswer(username, fileName, accept);
		}
		return m;
	}
	

	/**
	 * Gets a new FileMessage object (Not on the lastest common project version, but damn they should have put it as deprecated instead of deleting!
	 * @param type (enum_type_message)
	 * @param username name of the message sender
	 * @param file file descriptor
	 * @return the message !
	 */
	public Message getNewMessage(enum_type_message type, String username, File file) {
		Message m=null;
		if (type==MessageFactory.enum_type_message.FILE){
			m = new FileMessage(username, file);
		}
		return m;
	}
	
}
